<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>
    </title>
    <meta name="format-detection" content="telephone=no, address=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="description" content="">
    <link rel="shortcut icon" href="https://zaoqi.chuangkapai.com/attachment/images/global/wechat.jpg">
    <script type="text/javascript" src="__FRONT__/js/util.js"></script>
    <script src="__FRONT__/js/require.js"></script>
    <script type="text/javascript" src="__FRONT__/js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="__FRONT__/js/mui.min.js"></script>
    <script type="text/javascript" src="__FRONT__/js/common.js"></script>
    <link href="__FRONT__/css/bootstrap.min.css" rel="stylesheet">
    <link href="__FRONT__/css/common.min.css" rel="stylesheet">
    <script type="text/javascript">
        if (navigator.appName == 'Microsoft Internet Explorer') {
            if (navigator.userAgent.indexOf("MSIE 5.0") > 0 || navigator.userAgent.indexOf("MSIE 6.0") > 0 || navigator.userAgent.indexOf("MSIE 7.0") > 0) {
                alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
            }
        }
    </script>
</head>
<body class="mui-ios mui-ios-11 mui-ios-11-0">
<div class="msg-box"></div>
<div class="container container-fill">
    <script>
        $(function () {
            $(document).on('input propertychange', '.js-mobile-val', function () {
                var mobile_value = $(this).val();
                var register_mode = $("#register_mode").val();
                if (register_mode == 'mobile' && mobile_value.length != '11') {
                    $('.js-check-mobile').removeClass('send-code');
                }
                if (register_mode == 'email' && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(mobile_value)) {
                    $('.js-check-mobile').removeClass('send-code');
                }
                if (register_mode == 'random' && !(mobile_value.length == '11' || /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(mobile_value))) {
                    $('.js-check-mobile').removeClass('send-code');
                }
                $.post("{:url('mobile_exist')}", {
                    'mobile': mobile_value,
                }, function (data) {
                    //  alert(data.code);
                    if (data.code == 0) {
                        $('.js-check-mobile').addClass('send-code');
                    } else if (data.code == 1) {
                        $('.js-check-mobile').removeClass('send-code');
                        showmsg(data.msg, 1);
                        return;
                    }
                });
            });


            $(document).on('click', '.send-code', function () {
                var username = $('#sendcode input[name="username"]').val();
                /*option = {
                    'btnElement': $('.send-code'),
                    'showElement': $('.js-timer'),
                    'btnTips': '<a class="send-code">重新获取验证码</a>',
                    'successCallback': function(ret, message) {
                        if (ret == '0') {
                            showmsg(message);
                            $('#sendcode').hide();
                            $('#codeverify').show();
                        } else {
                            showmsg(message);
                            $('#sendcode').show();
                            $('#codeverify').hide();
                            return;
                        }
                    }
                };*/
                $.post("{:url('User/getRepwdCode')}", {'mobile': username}, function (res) {
                    if (res.code == '0') {
                        $('#sendcode').hide();
                        $('#codeverify').show();
                        showmsg(res.msg,0);
                        var downcount = 60;
                        $('.js-timer').html(downcount + '秒后重新获取');
                        var timer = setInterval(function () {
                            downcount--;
                            if (downcount <= 0) {
                                clearInterval(timer);
                                downcount = 60;
                                $('.js-timer').html('<a class="send-code">重新获取验证码</a>');
                                // $('.js-timer').html('uniacid', '1');
                            } else {
                                $('.js-timer').html(downcount + "秒后重新获取");
                                //$('.js-0`
                            }
                        }, 1000);
                    } else {
                        showmsg(res.msg, 1);
                        $('#sendcode').show();
                        $('#codeverify').hide();
                        return;
                    }
                });


                //sendCode(username,option);
            });

            $(document).on('click', '.check-verify', function () {
                var code = $('#codeverify input[name="code"]').val();
                if (!code) {
                    util.toast('未填写验证码', '', 'error');
                    return;
                }
                if (code.length < 4) {
                    util.toast('验证码少于四位', '', 'error');
                    return;
                }
                var username = $('#sendcode input[name="username"]').val();
                $.post("{:url('User/verifycode')}", {
                    'code': code,
                    'username': username,
                    'code_type': 1
                }, function (dat) {
                    if (dat.code == 1) {
                        util.toast(dat.msg, '', 'error');
                        return;
                    }
                    if (dat.code == 0) {
                        $('#codeverify').hide();
                        $('#reset').show();
                        $('#reset .js-reset').text(username);
                        return;
                    }

                });
            });
            $(document).on('click', '.resetpassword', function () {
                var password = $('#reset input[name="password"]').val();
                var repassword = $('#reset input[name="repassword"]').val();
                if (password == '' || repassword == '') {
                    util.toast('请填写密码', '', 'error');
                    return;
                }
                if (password.length < 6) {
                    util.toast('密码不能少于六位数', '', 'error');
                    return;
                }
                if (password != repassword) {
                    util.toast('两次密码输入不一致', '', 'error');
                    return;
                }
                var username = $('#sendcode input[name="username"]').val();
                params = {username, password, repassword};
                $.post("{:url('User/reset')}", {
                    'username': username,
                    'password': password,
                    'repassword': repassword
                }, function (dat) {
                    if (dat.code != 0) {
                        util.toast(dat.msg, '', 'error');
                    } else {
                        util.toast('设置密码成功');
                        setTimeout(function () {
                            location.href = "{:url('user/index')}";
                        },2000);
                        return;
                    }
                });
            });
        });
    </script>
    <div class="mui-content">
        <input type="hidden" value="random" id="register_mode">
        <div id="sendcode">
            <div class="mui-content-padded mui-text-muted">请输入手机号/邮箱,以收取验证码</div>
            <div class="mui-input-group mui-mt15">
                <div class="mui-input-row mui-help">
                    <input name="username" type="text" class="js-mobile-val" placeholder="手机号/邮箱">
                </div>
            </div>
            <div class="mui-content-padded">
                <button class="mui-btn mui-btn-success mui-btn-block js-check-mobile" uniacid="1">下一步</button>
            </div>
        </div>
        <div id="codeverify" style="display:none;">
            <div class="mui-content-padded mui-text-muted">您的手机号/邮箱<span class="mui-text-success"></span>会收到一条含有4位数字验证码的短息
            </div>
            <div class="mui-input-group mui-mt15">
                <div class="mui-input-row mui-help">
                    <input type="text" placeholder="请输入验证码" name="code">
                </div>
            </div>
            <div class="mui-content-padded mui-text-center">
                <button class="mui-btn mui-btn-success mui-btn-block check-verify">下一步</button>
                <div class="mui-mt15 mui-text-center">
				<span class="mui-text-muted js-timer">

				</span>
                </div>
            </div>
        </div>
        <div id="reset" style="display:none;">
            <div class="mui-content-padded mui-text-muted">请为你的账号<span class="mui-ml5 mui-mr5 js-reset"></span>设置密码,以保证下次正常登录
            </div>
            <div class="mui-input-group">
                <div class="mui-input-row">
                    <input name="password" type="password" placeholder="请设置密码">
                </div>
                <div class="mui-input-row">
                    <input name="repassword" type="password" placeholder="确认新密码">
                </div>
            </div>
            <div class="mui-content-padded mui-text-muted">密码为6~16位数字或字母</div>
            <div class="mui-content-padded">
                <button class="mui-btn mui-btn-success mui-btn-block resetpassword">确认</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>